package com.xebest.web.controller.purchase;  

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.junit.Test;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xebest.api.dto.XeVenSupplierInfoRequestDTO;
import com.xebest.web.XeVenBaseTest;
import com.xebest.web.form.XeVenPurchProductForm;
import com.xebest.web.form.XeVenPurchSupAptitudeForm;
import com.xebest.web.form.XeVenPurchSupBankForm;
import com.xebest.web.form.XeVenPurchSupContractForm;
import com.xebest.web.form.XeVenPurchSupInfoForm;
import com.xebest.web.form.XeVenPurchSupLinkmanForm;

/**  
 * @desc: 供货商相关
 * @author: 李书峰
 * @createTime: 2017年6月28日 下午3:18:36  
 * @history:  
 * @version: v1.0    
 */
public class XeVenSupplierController  extends XeVenBaseTest{

private static String URL_PREFIX = "http://localhost/supplier";
private static String URL_PREFIX2 = "http://localhost/restapi/supplier";	
	
	/**
	 * 新增供货商
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午3:27:07  
	 * @history:   void
	 */
	@Test
	public void insertSupplier() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setShopCode("qqqq");
			form.setBecomeVendor(1);
			form.setInvoiceRate(111);
			form.setInvoiceType(2);
			form.setPaymentDays(3);
			form.setPayType(2);
			form.setSettlementCycle(11);
			form.setSettlementWay(3);
			form.setSupplierName("供应商姓名");
			form.setSupplierStatus(2);
			form.setCheckStatus(2);
			form.setSupplierType(1);
			form.setSettlementTimeUnit(1);
			
			XeVenPurchSupBankForm bank = new XeVenPurchSupBankForm();
			bank.setAccBank("建设银行");
			bank.setBankAccCard("1234567");
			bank.setBankAccName("张三");
			form.setBank(bank);
			
			List<XeVenPurchSupLinkmanForm> linkmanList = new ArrayList<XeVenPurchSupLinkmanForm>();
			for(int i=0 ; i<2 ; i++){
				XeVenPurchSupLinkmanForm linkman = new XeVenPurchSupLinkmanForm();
				if(i == 0){
					linkman.setFirstLinkMan(1);
				}else{
					linkman.setFirstLinkMan(2);
				}
				linkman.setAreaId(1);
				linkman.setCityId(1);
				linkman.setLinkMobile("111111"+i);
				linkman.setLinkName("联系人"+i);
				linkman.setLinkPhone("2222"+i);
				linkman.setProvinceId(1);
				linkman.setStreet("街道"+i);
				linkmanList.add(linkman);
			}
			form.setLinkmanList(linkmanList);
			
			List<XeVenPurchSupAptitudeForm> aptitudeList = new ArrayList<XeVenPurchSupAptitudeForm>();
			for(int i=0 ; i<2 ; i++){
				XeVenPurchSupAptitudeForm aptitude = new XeVenPurchSupAptitudeForm();
				aptitude.setApName("证件"+i);
				aptitude.setApUrl("iiiiii"+i);
				aptitudeList.add(aptitude);
			}
			form.setAptitudeList(aptitudeList);
			
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/insertSupplier", form, String.class);
			assertSucces(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	
	/**
	 * 编辑供货商
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午3:27:07  
	 * @history:   void
	 */
	@Test
	public void updateSupplier() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setSupplierCode("GHS17071992700008");			
			form.setVersion(0);
			form.setBecomeVendor(1);
			form.setInvoiceRate(111);
			form.setInvoiceType(2);
			form.setPaymentDays(3);
			form.setPayType(2);
			form.setSettlementCycle(11);
			form.setSettlementWay(3);
			form.setSupplierName("供应商");
			form.setSupplierStatus(1);
			form.setSupplierType(1);
			
			XeVenPurchSupBankForm bank = new XeVenPurchSupBankForm();
			bank.setAccBank("交通银行");
			bank.setBankAccCard("56789");
			bank.setBankAccName("李四");
			form.setBank(bank);
			
			List<XeVenPurchSupLinkmanForm> linkmanList = new ArrayList<XeVenPurchSupLinkmanForm>();
			for(int i=0 ; i<2 ; i++){
				XeVenPurchSupLinkmanForm linkman = new XeVenPurchSupLinkmanForm();
				if(i == 0){
					linkman.setFirstLinkMan(1);
				}else{
					linkman.setFirstLinkMan(2);
				}
				linkman.setAreaId(1);
				linkman.setCityId(1);
				linkman.setLinkMobile("3333"+i);
				linkman.setLinkName("联系人"+i);
				linkman.setLinkPhone("44444"+i);
				linkman.setProvinceId(1);
				linkman.setStreet("街道"+i);
				linkmanList.add(linkman);
			}
			form.setLinkmanList(linkmanList);
			
			List<XeVenPurchSupAptitudeForm> aptitudeList = new ArrayList<XeVenPurchSupAptitudeForm>();
			for(int i=3 ; i<4 ; i++){
				XeVenPurchSupAptitudeForm aptitude = new XeVenPurchSupAptitudeForm();
				aptitude.setApName("证件"+i);
				aptitude.setApUrl("iiiiii"+i);
				aptitudeList.add(aptitude);
			}
			form.setAptitudeList(aptitudeList);
			
			List<XeVenPurchSupContractForm> contractList = new ArrayList<XeVenPurchSupContractForm>();
			for(int i=0 ; i<2 ; i++){
				XeVenPurchSupContractForm contract = new XeVenPurchSupContractForm();
				contract.setContractSort(i);
				contract.setContractUrl(i+i+i+i+i+i+i+i+"llllll");
				contract.setFileType(1);
				contract.setSignMan("hehe");
				contract.setSignTime(new Date());
				contract.setStartTime(new Date());
				contract.setEndTime(new Date());
				contractList.add(contract);
			}
			form.setContractList(contractList);
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/updateSupplier", form, String.class);
//			System.out.println(retMsg);
			assertSucces(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	
	/**
	 * 删除供货商
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午3:27:07  
	 * @history:   void
	 */
	@Test
	public void delSupplier() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setSupplierCode("GHS17071711920006");			
			form.setSupplierStatus(1);
			form.setCheckStatus(1);
			form.setVersion(1);
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/delSupplier", form, String.class);
//			System.out.println(retMsg);
			assertSucces(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	
	/**
	 * 商品审核供货商
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午3:27:07  
	 * @history:   void
	 */
	@Test
	public void purchCheck() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setSupplierCode("GHS17071821490007");
			form.setCheckStatus(4);
			form.setSupplierStatusPre(2);
			form.setCheckStatusPre(2);
			form.setSupplierStatus(2);
			form.setVersion(2);
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/purchCheck", form, String.class);
			assertSucces(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}

	/**
	 * 商品驳回供货商
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午3:27:07  
	 * @history:   void
	 */
	@Test
	public void purchReject() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setSupplierCode("GHS17071821490007");
			form.setCheckStatus(3);
			form.setSupplierStatusPre(2);
			form.setCheckStatusPre(2);
			form.setSupplierStatus(2);
			form.setPurchRejectReason("商品部驳回原因");
			form.setVersion(2);
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/purchReject", form, String.class);
			assertSucces(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	
	/**
	 * 财务审核供货商
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午3:27:07  
	 * @history:   void
	 */
	@Test
	public void financeCheck() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setSupplierCode("GHS17071821490007");
			form.setCheckStatus(6);
			form.setSupplierStatus(2);
			form.setVersion(3);
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/financeCheck", form, String.class);
			assertSucces(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	
	/**
	 * 财务驳回供货商
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午3:27:07  
	 * @history:   void
	 */
	@Test
	public void financeReject() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setSupplierCode("GHS17071821490007");
			form.setCheckStatus(5);
			form.setSupplierStatus(2);
			form.setCheckStatusPre(4);
			form.setSupplierStatusPre(2);
			form.setFinanceRejectReason("财务部驳回原因");
			form.setVersion(3);
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/financeReject", form, String.class);
			assertSucces(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	
	/**
	 * 签订供货商
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午3:27:07  
	 * @history:   void
	 */
	@Test
	public void signSupplier() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setSupplierCode("GHS17073126570019");
			form.setCheckStatus(7);
			form.setCheckStatusPre(6);
			form.setSupplierStatus(3);
			form.setSupplierStatusPre(2);
			XeVenPurchSupContractForm con = new XeVenPurchSupContractForm();
			con.setStartTimeStr("2017-03-02");
			con.setEndTimeStr("2022-03-02");
			form.setContractForm(con);
			List<String> fileList = new ArrayList<String>();
			fileList.add("url");
			form.setFileList(fileList);
			form.setVersion(9);
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/signSupplier", form, String.class);
			System.out.println(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	
	/**
	 * 冻结供货商
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午3:27:07  
	 * @history:   void
	 */
	@Test
	public void frozenSupplier() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			List<XeVenPurchSupInfoForm> list = new ArrayList<XeVenPurchSupInfoForm>();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setSupplierCode("GHS17071821490007");
			form.setSupplierStatus(4);
			form.setSupplierStatusPre(3);
			form.setCheckStatusPre(7);
			form.setVersion(5);
			XeVenPurchSupInfoForm form1 = new XeVenPurchSupInfoForm();
			form1.setSupplierCode("GHS17071992700008");
			form1.setSupplierStatus(4);
			form1.setSupplierStatusPre(3);
			form1.setCheckStatusPre(7);
			form1.setVersion(1);
			list.add(form);
			list.add(form1);
			System.out.println(JSONArray.toJSON(list).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/frozenSupplier", list, String.class);
			System.out.println(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	
	/**
	 * 解冻供货商
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午3:27:07  
	 * @history:   void
	 */
	@Test
	public void freeSupplier() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			List<XeVenPurchSupInfoForm> list = new ArrayList<XeVenPurchSupInfoForm>();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setSupplierCode("GHS17071821490007");
			form.setSupplierStatus(3);
			form.setSupplierStatusPre(4);
			form.setCheckStatusPre(7);
			form.setVersion(5);
			XeVenPurchSupInfoForm form1 = new XeVenPurchSupInfoForm();
			form1.setSupplierCode("GHS17071992700008");
			form1.setSupplierStatus(3);
			form1.setSupplierStatusPre(4);
			form1.setCheckStatusPre(7);
			form1.setVersion(5);
			list.add(form);
			list.add(form1);
			System.out.println(JSONArray.toJSON(list).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/freeSupplier", list, String.class);
			System.out.println(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	
	/**
	 * 查询供货商列表
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午4:21:00  
	 * @history:   void
	 */
	@Test
	public void querySupplierList() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setPageNum(1);
			form.setPageSize(10);
			form.setSupplierType(1);
			form.setSupplierStatus(4);
			form.setCheckStatus(7);
			form.setSearchText("GHS17071821490007");
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/querySupplierList", form, String.class);
			System.out.println(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	

	/**
	 * 查询供货商审核列表
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午4:21:00  
	 * @history:   void
	 */
		@Test
	public void querySupplierCheckList() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setPageNum(1);
			form.setPageSize(10);
			form.setCheckStatus(4);
			form.setSearchText("GHS17071821490007");
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/querySupplierCheckList", form, String.class);
			System.out.println(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	
	/**供货商详情
	 * querySupplierDetail
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午4:55:15  
	 * @history:   void
	 */
	@Test
	public void querySupplierDetail() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setSupplierCode("GHS17073126570019");
			form.setVersion(0);
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/querySupplierDetail", form, String.class);
			System.out.println(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	
	/**
	 * 查询历史签订
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午4:56:38  
	 * @history:   void
	 */
	@Test
	public void queryContractList() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setSupplierCode("GHS17073126570019");
	//		form.setSupplierStatus(4);
	//		form.setVersion(5);
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/queryContractList", form, String.class);
			assertSucces(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}

	/**
	 * 查询合同文件
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午4:56:38  
	 * @history:   void
	 */
	@Test
	public void queryContractFileList() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setSupplierCode("GHS17071992700008");
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/queryContractFileList", form, String.class);
			assertSucces(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	
	/**
	 * 查询供货商商品购买记录列表
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午4:57:17  
	 * @history:   void
	 */
	@Test
	public void queryProductList() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchProductForm form = new XeVenPurchProductForm();
			form.setSearchText("eee");
			form.setCategoryCode("1_2_3");
			form.setSupplierName("hehe");
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/queryProductList", form, String.class);
			System.out.println(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	/**
	 * api查询供货商code接口
	 * @author: 李书峰
	 * @createTime: 2017年7月11日 下午4:01:50  
	 * @history:   void
	 */
	@Test
	public void querySupplierCodes(){
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenSupplierInfoRequestDTO dto = new XeVenSupplierInfoRequestDTO();
			dto.setSupplierName("供货商");
			dto.setSupplierCode("GHS17071821490007");
			List<String> codeList = new ArrayList<String>();
			codeList.add("GHS17071821490007");
			dto.setCodeList(codeList);
			System.out.println(JSONObject.toJSON(dto).toString());
			String retMsg = restTemplate.postForObject("http://localhost/restapi/supplier/queryCodes", dto, String.class);
			assertSucces(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}

	/**
	 * 查询商户列表
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午4:57:17  
	 * @history:   void
	 */
	@Test
	public void queryShopList() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchProductForm form = new XeVenPurchProductForm();
			form.setSearchText("三只兔子");
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/queryShopList", form, String.class);
			System.out.println(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}

	/**
	 * 查询商户详情
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午4:57:17  
	 * @history:   void
	 */
	@Test
	public void queryShopDetail() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setUserCode("SH170713840165");
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/queryShopDetail", form, String.class);
			System.out.println(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}

	/**
	 * 查询商户详情列表
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午4:57:17  
	 * @history:   void
	 */
	@Test
	public void queryShops() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchProductForm form = new XeVenPurchProductForm();
			form.setPageNum(1);
			form.setPageSize(10);
			form.setSearchText("三只兔子");
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/queryShops", form, String.class);
			System.out.println(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}

	/**
	 * 供货商搜索列表
	 * @author: 李书峰
	 * @createTime: 2017年6月28日 下午4:57:17  
	 * @history:   void
	 */
	@Test
	public void searchSupplierList() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchSupInfoForm form = new XeVenPurchSupInfoForm();
			form.setPageNum(1);
			form.setPageSize(10);
			form.setSearchType(1);
			form.setSearchText("GHS1708283650035");
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/searchSupplierList", form, String.class);
			System.out.println(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	@Test
	public void listPurchSupInfo() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenSupplierInfoRequestDTO form = new XeVenSupplierInfoRequestDTO();
			form.setSupplierCode("898333");
			form.setSupplierName("");
			String retMsg = restTemplate.postForObject(URL_PREFIX2 + "/listPurchSupInfo", form, String.class);
			System.out.println(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
}
  
